package com.rogchen.security.securitycustomuser.vo;

import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;

@Data
public class SysUserVo implements UserDetails, Serializable {

    private String username;

    private String password;

    private String roleCode;

    private String delFlag;
    private boolean accountNonExpired;
    private boolean accountNonLocked;
    private boolean credentialsNonExpired;
    private boolean enabled;
    private List<SimpleGrantedAuthority> authorities;

    public SysUserVo(String username, String password, String roleCode) {
        this.username = username;
        this.password = password;
        this.roleCode = roleCode;
    }

    public SysUserVo(String username, String password, List<SimpleGrantedAuthority> authorities) {
        this.username = username;
        this.password = password;
        this.authorities = authorities;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
//        return AuthorityUtils.commaSeparatedStringToAuthorityList("roleCode");
    }

    public boolean isAccountNonExpired() {
        return accountNonExpired;
    }

    public boolean isAccountNonLocked() {
        return accountNonLocked;
    }

    public boolean isCredentialsNonExpired() {
        return credentialsNonExpired;
    }

    public boolean isEnabled() {
        return enabled;
    }
}